package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.testng.AssertJUnit.assertFalse;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.framework.Contacts;
import com.example.objects.ContactObject;

public class ContactRemovalTests extends TestBase {

	@Test
	public void testContactCanBeRemoved() throws Exception {
		Contacts oldContacts = app.getContactHelper().getContacts();
		assertFalse("There are 0 contacts. Nothing to delete!", (oldContacts.size() == 0));
		ContactObject contactToRemove = oldContacts.getSomeContact();
		System.out.println(contactToRemove.toString());
		app.getContactHelper().removeContact(contactToRemove);
		Contacts newContacts = app.getContactHelper().getContacts();
		assertThat(newContacts, equalTo(oldContacts.without(contactToRemove)));
	}
	
	@AfterMethod
	public void testUiAndDbConformWithDb() {
		if (app.getProperty("ui.check") != null) {
			Contacts modelList = app.getContactHelper().getContacts();
			Contacts uiList = app.getContactHelper().getUiContacts();
			assertThat(uiList, equalTo(modelList));
		}
		if (app.getProperty("db.check") != null) {
			Contacts modelList = app.getContactHelper().getContacts();
			Contacts dbList = app.getHibernateHelper().getContacts();
			assertThat(dbList, equalTo(modelList));
		}

	}
}
